package com.lanou3g.ptp.api.web.controller;

import com.lanou3g.ptp.api.service.ApiGradeService;
import com.lanou3g.ptp.entity.GradeRole;
import com.lanou3g.utils.PtpResult;
import com.lanou3g.utils.PtpResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "打分接口")
@RestController
public class GradeRoleController {
    @Autowired
    private ApiGradeService apiGradeService;

    //    添加一个gradeRole
    @ApiOperation("添加一个学生信息")
    @PostMapping("/grade")
    public PtpResult addGradeRole(GradeRole gradeRole) {
        try {
            System.out.println("进入service");
            PtpResult ptpResult = apiGradeService.addGrade(gradeRole);
            System.out.println("进入service后");
            return PtpResultUtils.ok(ptpResult);
        } catch (Exception e) {
            e.printStackTrace();
            return PtpResultUtils.error(533);
        }
    }


    //    根据id删除学生的成绩
    @ApiOperation("根据id删除学生的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "gradeId")
    })
    @DeleteMapping("/grade/{id}")
    public PtpResult deleteById(@PathVariable Long id) {
        try {
            PtpResult ptpResult = apiGradeService.deleteById(id);
            return PtpResultUtils.ok(ptpResult);
        } catch (Exception e) {
            e.printStackTrace();
            return PtpResultUtils.error(533);
        }

    }

    //    更改学生的成绩
    @ApiOperation("根据id更改学生的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "gradeId")
    })
    @PutMapping("/gradeRole/{id}")
    public PtpResult updateGradeRole(@PathVariable Long id, GradeRole gradeRole) {
        try {
            PtpResult ptpResult = apiGradeService.update(gradeRole);
            return PtpResultUtils.ok(ptpResult);
        } catch (Exception e) {
            e.printStackTrace();
            return PtpResultUtils.error(533);
        }
    }
}
